package com.caigou.controller.front;

import com.caigou.bean.cms.param.ArticleDynamicParam;
import com.caigou.bean.cms.param.ArticleTdkParam;
import com.caigou.bean.cms.param.FontArticlePram;
import com.caigou.bean.vo.ChannelTdkVO;
import com.caigou.mapper.cms.FooterConfigMapper;
import com.caigou.mapper.cms.FriendshipLinkMapper;
import com.caigou.pojo.ArticleList;
import com.caigou.service.ArticleService;
import com.caigou.service.ChannelService;
import com.caigou.util.Result;
import com.caigou.util.StringUtil;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.utils.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@Slf4j
@Controller
@RequestMapping
public class FrontListController {

    @Value("${domain}")
    private String domain;

    @Resource
    private ChannelService channelService;

    @Resource
    FriendshipLinkMapper friendshipLinkMapper;

    @Resource
    FooterConfigMapper footerConfigMapper;

    @Resource
    RestTemplate restTemplate;

    @Resource
    private ArticleService articleService;


    // Rss静态化处理
    @RequestMapping(value="rssList/{pageNum}", method = RequestMethod.GET)
    public String queryRssList(ModelMap map,@PathVariable(name="pageNum")Integer pageNum,
                              HttpServletRequest request){
//        String plateIds = request.getParameter("plateIds");
        log.info("pageNum={}",pageNum);
        FontArticlePram param = new FontArticlePram();
        param.setPlateIds("-1");
        param.setSize(12);
        param.setPage(pageNum);
        Result<PageInfo<ArticleList>> pageInfoResult = articleService.findArticleListByPlateId(param);
        map.put("pageInfoResult",pageInfoResult);
        log.info("pageInfoResult=,{}",pageInfoResult);

        ArticleTdkParam articleTdkParam = new ArticleTdkParam();
        articleTdkParam.setPlateIds("101");
        Result  resultChannelTdkVO = articleService.findArticleDynamicTdk(articleTdkParam);
        log.info("resultChannelTdkVO=,{}",resultChannelTdkVO);
        map.put("resultChannelTdkVO",resultChannelTdkVO);

        return "/web/html/list/rssList";
    }

    // 首页
    @RequestMapping(value = "headerList/{pageNum}",method = RequestMethod.GET)
    public String queryHeaderList(ModelMap map,@PathVariable(name = "pageNum") Integer pageNum,
                                  HttpServletRequest request){

        String plateIds = request.getParameter("id");
        if(StringUtils.isEmpty(plateIds)){
            return "参数错误";
        }
        String column = request.getParameter("column");
        log.info("进入purchaserList 参数plateIds=,column=,{},{}",plateIds,column);
        map.put("column",column);
        map.put("plateIds",plateIds);
        FontArticlePram param = new FontArticlePram();
        param.setPlateIds(plateIds);
        param.setSize(12);
        param.setPage(pageNum);
        Result<PageInfo<ArticleList>> result = articleService.findArticleListByPlateId(param);
        map.put("result",result);
        log.info("result=,{}",result);

        ArticleTdkParam articleTdkParam = new ArticleTdkParam();
        articleTdkParam.setPlateIds(plateIds);
        Result  channelTdkVO = articleService.findArticleDynamicTdk(articleTdkParam);
        log.info("channelTdkVO=,{}",channelTdkVO);
        map.put("channelTdkVO",channelTdkVO);

        map.put("domain",domain);
        return "/web/html/list/headerList";
    }

    //专业-> 采购人
    @RequestMapping(value = "purchaserList/{pageNum}",method = RequestMethod.GET)
    public String queryPurchaserList(ModelMap map,@PathVariable(name = "pageNum") Integer pageNum,
                                     HttpServletRequest request){
        String plateIds = request.getParameter("id");
        if(StringUtils.isEmpty(plateIds)){
            return "参数错误";
        }
        String column = request.getParameter("column");
        log.info("进入purchaserList 参数plateIds=,column=,{},{}",plateIds,column);

        map.put("column",column);
        map.put("plateIds",plateIds);
        FontArticlePram param = new FontArticlePram();
        param.setPlateIds(plateIds);
        param.setSize(12);
        param.setPage(pageNum);
        Result result = articleService.findArticleListByPlateId(param);
        map.put("result",result);

        ArticleTdkParam tdkParam = new ArticleTdkParam();
        tdkParam.setPlateIds(plateIds);
        Result channelTdkVO = articleService.findArticleDynamicTdk(tdkParam);
        map.put("channelTdkVO",channelTdkVO);

        map.put("domain",domain);
        return "/web/html/list/purchaserList";
    }

    //专业-> 实务
    @RequestMapping(value = "practiceList/{pageNum}",method = RequestMethod.GET)
    public String queryPracticeList(ModelMap map,@PathVariable(name = "pageNum") Integer pageNum,
                                    HttpServletRequest request){
        String plateIds = request.getParameter("id");
        if(StringUtils.isEmpty(plateIds)){
            return "参数错误";
        }
        String column = request.getParameter("column");
        log.info("进入practiceList 参数plateIds=,column=,{},{}",plateIds,column);

        map.put("column",column);
        map.put("plateIds",plateIds);
        FontArticlePram param = new FontArticlePram();
        param.setPlateIds(plateIds);
        param.setSize(12);
        param.setPage(pageNum);
        Result result = articleService.findArticleListByPlateId(param);
        map.put("result",result);

        ArticleTdkParam tdkParam = new ArticleTdkParam();
        tdkParam.setPlateIds(plateIds);
        Result channelTdkVO = articleService.findArticleDynamicTdk(tdkParam);
        map.put("channelTdkVO",channelTdkVO);

        map.put("domain",domain);
        return "/web/html/list/practiceList";
    }

    //专业-> 监管
    @RequestMapping(value = "superviseList/{pageNum}",method = RequestMethod.GET)
    public String querySuperviseList(ModelMap map,@PathVariable(name = "pageNum") Integer pageNum,
                                     HttpServletRequest request){
        String plateIds = request.getParameter("id");
        if(StringUtils.isEmpty(plateIds)){
            return "参数错误";
        }
        String column = request.getParameter("column");
        log.info("进入superviseList 参数plateIds=,column=,{},{}",plateIds,column);

        map.put("column",column);
        map.put("plateIds",plateIds);
        FontArticlePram param = new FontArticlePram();
        param.setPlateIds(plateIds);
        param.setSize(12);
        param.setPage(pageNum);
        Result result = articleService.findArticleListByPlateId(param);
        map.put("result",result);

        ArticleTdkParam tdkParam = new ArticleTdkParam();
        tdkParam.setPlateIds(plateIds);
        Result channelTdkVO = articleService.findArticleDynamicTdk(tdkParam);
        map.put("channelTdkVO",channelTdkVO);

        map.put("domain",domain);
        return "/web/html/list/superviseList";
    }

    //专业-> 军队
    @RequestMapping(value = "armyList/{pageNum}",method = RequestMethod.GET)
    public String queryArmyList(ModelMap map,@PathVariable(name = "pageNum") Integer pageNum,
                                HttpServletRequest request){
        String plateIds = request.getParameter("id");
        if(StringUtils.isEmpty(plateIds)){
            return "参数错误";
        }
        String column = request.getParameter("column");
        log.info("进入armyList 参数plateIds=,column=,{},{}",plateIds,column);

        map.put("column",column);
        map.put("plateIds",plateIds);
        FontArticlePram param = new FontArticlePram();
        param.setPlateIds(plateIds);
        param.setSize(12);
        param.setPage(pageNum);
        Result result = articleService.findArticleListByPlateId(param);
        map.put("result",result);

        ArticleTdkParam tdkParam = new ArticleTdkParam();
        tdkParam.setPlateIds(plateIds);
        Result channelTdkVO = articleService.findArticleDynamicTdk(tdkParam);
        map.put("channelTdkVO",channelTdkVO);

        map.put("domain",domain);
        return "/web/html/list/armyList";
    }

    //专业-> 研究院
    @RequestMapping(value = "instituteList/{pageNum}",method = RequestMethod.GET)
    public String queryInstituteList(ModelMap map,@PathVariable(name = "pageNum") Integer pageNum,
                                     HttpServletRequest request){
        String plateIds = request.getParameter("id");
        if(StringUtils.isEmpty(plateIds)){
            return "参数错误";
        }
        String column = request.getParameter("column");
        log.info("进入armyList 参数plateIds=,column=,{},{}",plateIds,column);

        map.put("column",column);
        map.put("plateIds",plateIds);
        FontArticlePram param = new FontArticlePram();
        param.setPlateIds(plateIds);
        param.setSize(12);
        param.setPage(pageNum);
        Result result = articleService.findArticleListByPlateId(param);
        map.put("result",result);

        ArticleTdkParam tdkParam = new ArticleTdkParam();
        tdkParam.setPlateIds(plateIds);
        Result channelTdkVO = articleService.findArticleDynamicTdk(tdkParam);
        map.put("channelTdkVO",channelTdkVO);

        map.put("domain",domain);
        return "/web/html/list/instituteList";
    }

    //专题-> 资讯专题
    @RequestMapping(value = "newsSpecialList/{pageNum}",method = RequestMethod.GET)
    public String queryNewsSpecialList(ModelMap modelMap,@PathVariable(name = "pageNum") Integer pageNum,
                                       HttpServletRequest request){
        String keyword = request.getParameter("keyword");
        log.info("进入queryNewsSpecialList 参数keyword={}",keyword);
        FontArticlePram pram = new FontArticlePram();
        pram.setPage(pageNum);
        pram.setSize(9);
        Result result = articleService.loadSpecialArticleList(pram);
        modelMap.put("result",result);

        ArticleTdkParam articleTdkParam = new ArticleTdkParam();
        articleTdkParam.setPlateIds("101");
        articleTdkParam.setKeyword(keyword);
        Result<ChannelTdkVO> channelTdkVO = articleService.findArticleDynamicTdk(articleTdkParam);
        modelMap.put("channelTdkVO",channelTdkVO);
        return "/web/html/list/newsSpecialList";
    }

    // tag-List
    @RequestMapping(value = "tagList/{pageNum}",method = RequestMethod.GET)
    public String queryTagList(ModelMap map,@PathVariable("pageNum") Integer pageNum,
                               HttpServletRequest request){
        String tag = request.getParameter("tag");
        String keyword = request.getParameter("id");
        String name = request.getParameter("name");
        map.put("tag",tag);
        map.put("id",keyword);
        log.info("进入queryTagList 传入的参数为 tag={},keyword={}",tag,keyword);
        ArticleDynamicParam param = new ArticleDynamicParam();
        param.setPageSize(12);
        param.setPageNum(pageNum);
        param.setTag(tag);
        param.setKeyword(keyword);
        Result result = articleService.findArticleByParam(param);
        map.put("result",result);
        map.put("name",name);

        ArticleTdkParam articleTdkParam = new ArticleTdkParam();
        articleTdkParam.setKeyword("101");
        articleTdkParam.setPlateIds(keyword);
        Result<ChannelTdkVO> channelTdkVO = articleService.findArticleDynamicTdk(articleTdkParam);
        map.put("channelTdkVO",channelTdkVO);

        map.put("domain",domain);
        return "/web/html/list/tagList";
    }

}
